package xj.graph2d.command;

import xj.graph2d.Command;
import xj.graph2d.GraphDocument;
import xj.graph2d.GraphNodeBase;

public class NodeMoveAuxAction implements Command.AuxAction {

  public NodeMoveAuxAction(GraphDocument graph, GraphNodeBase node, float dx,
      float dy) {
    this.graph = graph;
    this.node = node;
    this.dx = dx;
    this.dy = dy;
  }

  public void forward() {
    if (graph != null && node != null) {
      node.moveNotify(dx, dy);
      graph.layoutAdjacentEdges(node);
    }
  }

  public void backward() {
    if (graph != null && node != null) {
      node.moveNotify(-dx, -dy);
      graph.layoutAdjacentEdges(node);
    }
  }

  public boolean isAlwaysAfter() {
    return false;
  }

  @Override
  public String toString() {
    return ("NodeMoveAuxAction: dx=" + dx + " dy=" + dy);
  }

  GraphDocument graph;

  GraphNodeBase node;

  float dx, dy;

}
